"""
YouTour - Create and access tours based on public transport routes. 
Copyright (C) 2011 Karl Beecher

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

from business.Tour import Tour
from business.StopFactory import StopFactory
from data.DbInterface import DbInterface
from datetime import datetime, time


class TourFactory():
    '''
    Provides an interface to outside classes to obtain youtour
    business objects
    '''

    @staticmethod
    def getAllTours():

        tourDbos = DbInterface.getAllTours()

        tours = []

        for tbo in tourDbos:
            tours.append(TourFactory.buildTourFromDbo(tbo))

        return tours

    '''
    Build a tour from a tour GAE model
    '''
    @staticmethod
    def buildTourFromDbo(tourDbo):
        t = Tour()
        t.tourId = tourDbo.key
        t.title = tourDbo.title
        t.description = tourDbo.description
        t.startTime = tourDbo.startTime
        t.endTime = tourDbo.endTime
        t.startPosition = tourDbo.startPosition
        t.endPosition = tourDbo.endPosition

        for sDbo in tourDbo.stops:
            t.stopList.append(StopFactory.buildStopFromDbo(sDbo))

        return t


    '''
    Build a tour from a tourId
    '''
    @staticmethod
    def buildTourFromId(tourId):

        tourDbo = DbInterface.getTourById(tourId)

        return TourFactory.buildTourFromDbo(tourDbo)


    @staticmethod
    def buildTour():
        newTour = Tour()

        return newTour
